home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / emacs.lha / emacs-19.16 / info / emacs-11 (.txt) < prev    next >
GNU Info File  |  1993-07-06  |  49KB  |  861 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.54 from the
  2. input file emacs.texi.
  3. File: emacs,  Node: ForIndent Num,  Next: ForIndent Conv,  Prev: ForIndent Cont,  Up: Fortran Indent
  4. Line Numbers
  5. ............
  6.    If a number is the first non-whitespace in the line, Fortran
  7. indentation assumes it is a line number and moves it to columns 0
  8. through 4.  (Columns always count from 0 in GNU Emacs.)
  9.    Line numbers of four digits or less are normally indented one space.
  10. The variable `fortran-line-number-indent' controls this; it specifies
  11. the maximum indentation a line number can have.  Line numbers are
  12. indented to right-justify them to end in column 4 unless that would
  13. require more than this maximum indentation.  The default value of the
  14. variable is 1.
  15.    Simply inserting a line number is enough to indent it according to
  16. these rules.  As each digit is inserted, the indentation is recomputed.
  17. To turn off this feature, set the variable
  18. `fortran-electric-line-number' to `nil'.  Then inserting line numbers
  19. is like inserting anything else.
  20. File: emacs,  Node: ForIndent Conv,  Next: ForIndent Vars,  Prev: ForIndent Num,  Up: Fortran Indent
  21. Syntactic Conventions
  22. .....................
  23.    Fortran mode assumes that you follow certain conventions that
  24. simplify the task of understanding a Fortran program well enough to
  25. indent it properly:
  26.    * Two nested `do' loops never share a `continue' statement.
  27.    * Fortran keywords such as `if', `else', `then', `do' and others are
  28.      written without embedded whitespace or line breaks.
  29.      Fortran compilers generally ignore whitespace outside of string
  30.      constants, but Fortran mode does not recognize these keywords if
  31.      they are not contiguous.  Constructs such as `else if' or `end do'
  32.      are acceptable, but the second word should be on the same line as
  33.      the first and not on a continuation line.
  34. If you fail to follow these conventions, the indentation commands may
  35. indent some lines unaesthetically.  However, a correct Fortran program
  36. retains its meaning when reindented even if the conventions are not
  37. followed.
  38. File: emacs,  Node: ForIndent Vars,  Prev: ForIndent Conv,  Up: Fortran Indent
  39. Variables for Fortran Indentation
  40. .................................
  41.    Several additional variables control how Fortran indentation works:
  42. `fortran-do-indent'
  43.      Extra indentation within each level of `do' statement (default 3).
  44. `fortran-if-indent'
  45.      Extra indentation within each level of `if' statement (default 3).
  46.      This value is also used for extra indentation within each level of
  47.      the Fortran 90 `where' statement.
  48. `fortran-structure-indent'
  49.      Extra indentation within each level of `structure', `union', or
  50.      `map' statements (default 3).
  51. `fortran-continuation-indent'
  52.      Extra indentation for bodies of continuation lines (default 5).
  53. `fortran-check-all-num-for-matching-do'
  54.      If this is `nil', indentation assumes that each `do' statement
  55.      ends on a `continue' statement.  Therefore, when computing
  56.      indentation for a statement other than `continue', it can save time
  57.      by not checking for a `do' statement ending there.  If this is
  58.      non-`nil', indenting any numbered statement must check for a `do'
  59.      that ends there.  The default is `nil'.
  60. `fortran-blink-matching-if'
  61.      If this is `t', indenting an `endif' statement moves the cursor
  62.      momentarily to the matching `if' statement to show where it is.
  63.      The default is `nil'.
  64. `fortran-minimum-statement-indent-fixed'
  65.      Minimum indentation for fortran statements when using fixed format
  66.      continuation line style.  Statement bodies are never indented less
  67.      than this much.  The default is 6.
  68. `fortran-minimum-statement-indent-tab'
  69.      Minimum indentation for fortran statements for tab format
  70.      continuation line style.  Statement bodies are never indented less
  71.      than this much.  The default is 8.
  72. File: emacs,  Node: Fortran Comments,  Next: Fortran Autofill,  Prev: Fortran Indent,  Up: Fortran
  73. Comments
  74. --------
  75.    The usual Emacs comment commands assume that a comment can follow a
  76. line of code.  In Fortran, the standard comment syntax requires an
  77. entire line to be just a comment.  Therefore, Fortran mode replaces the
  78. standard Emacs comment commands and defines some new variables.
  79.    Fortran mode can also handle a nonstandard comment syntax where
  80. comments start with `!' and can follow other text.  Because only some
  81. Fortran compilers accept this syntax, Fortran mode will not insert such
  82. comments unless you have said in advance to do so.  To do this, set the
  83. variable `comment-start' to `"!"' (*note Variables::.).
  84. `M-;'
  85.      Align comment or insert new comment (`fortran-comment-indent').
  86. `C-x ;'
  87.      Applies to nonstandard `!' comments only.
  88. `C-c ;'
  89.      Turn all lines of the region into comments, or (with argument)
  90.      turn them back into real code (`fortran-comment-region').
  91.    `M-;' in Fortran mode is redefined as the command
  92. `fortran-comment-indent'.  Like the usual `M-;' command, this
  93. recognizes any kind of existing comment and aligns its text
  94. appropriately; if there is no existing comment, a comment is inserted
  95. and aligned.  But inserting and aligning comments are not the same in
  96. Fortran mode as in other modes.
  97.    When a new comment must be inserted, if the current line is blank, a
  98. full-line comment is inserted.  On a non-blank line, a nonstandard `!'
  99. comment is inserted if you have said you want to use them.  Otherwise a
  100. full-line comment is inserted on a new line before the current line.
  101.    Nonstandard `!' comments are aligned like comments in other
  102. languages, but full-line comments are different.  In a standard
  103. full-line comment, the comment delimiter itself must always appear in
  104. column zero.  What can be aligned is the text within the comment.  You
  105. can choose from three styles of alignment by setting the variable
  106. `fortran-comment-indent-style' to one of these values:
  107. `fixed'
  108.      Align the text at a fixed column, which is the sum of
  109.      `fortran-comment-line-extra-indent' and the minimum statement
  110.      indentation.  This is the default.
  111.      The minimum statement indentation is
  112.      `fortran-minimum-statement-indent-fixed' for fixed format
  113.      continuation line style and `fortran-minimum-statement-indent-tab'
  114.      for tab format style.
  115. `relative'
  116.      Align the text as if it were a line of code, but with an additional
  117.      `fortran-comment-line-extra-indent' columns of indentation.
  118. `nil'
  119.      Don't move text in full-line columns automatically at all.
  120.    In addition, you can specify the character to be used to indent
  121. within full-line comments by setting the variable
  122. `fortran-comment-indent-char' to the single-character string you want
  123. to use.
  124.    Fortran mode introduces two variables `comment-line-start' and
  125. `comment-line-start-skip' which play for full-line comments the same
  126. roles played by `comment-start' and `comment-start-skip' for ordinary
  127. text-following comments.  Normally these are set properly by Fortran
  128. mode so you do not need to change them.
  129.    The normal Emacs comment command `C-x ;' has not been redefined.  If
  130. you use `!' comments, this command can be used with them.  Otherwise it
  131. is useless in Fortran mode.
  132.    The command `C-c ;' (`fortran-comment-region') turns all the lines
  133. of the region into comments by inserting the string `C$$$' at the front
  134. of each one.  With a numeric argument, it turns the region back into
  135. live code by deleting `C$$$' from the front of each line in it.  The
  136. string used for these comments can be controlled by setting the
  137. variable `fortran-comment-region'.  Note that here we have an example
  138. of a command and a variable with the same name; these two uses of the
  139. name never conflict because in Lisp and in Emacs it is always clear
  140. from the context which one is meant.
  141. File: emacs,  Node: Fortran Autofill,  Next: Fortran Columns,  Prev: Fortran Comments,  Up: Fortran
  142. Fortran Auto Fill Mode
  143. ----------------------
  144.    Fortran Auto Fill mode is a minor mode which automatically splits
  145. Fortran statements as you insert them when they become too wide.
  146. Splitting a statement involves making continuation lines.  This
  147. splitting happens when you type SPC, RET, or TAB, and also in the
  148. Fortran indentation commands.
  149.    `M-x fortran-auto-fill-mode' turns Fortran Auto Fill mode on if it
  150. was off, or off if it was on.  This command works the same as `M-x
  151. auto-fill-mode' does for normal Auto Fill mode (*note Filling::.).  A
  152. positive numeric argument turns Fortran Auto Fill mode on, and a
  153. negative argument turns it off.  You can see when Fortran Auto Fill mode
  154. is in effect by the presence of the word `Fill' in the mode line,
  155. inside the parentheses.  Fortran Auto Fill mode is a minor mode, turned
  156. on or off for each buffer individually.  *Note Minor Modes::.
  157.    Fortran Auto Fill mode breaks lines at spaces or delimiters when the
  158. lines get longer than the desired width (the value of `fill-column').
  159. The delimiters that Fortran Auto Fill mode may break at are `,', `'',
  160. `+', `-', `/', `*', `=', and `)'.  The line break comes after the
  161. delimiter if the variable `fortran-break-before-delimiters' is `nil'.
  162. Otherwise (and by default), the break comes before the delimiter.
  163.    By default, Fortran Auto Fill mode is not enabled.  If you want this
  164. feature turned on permanently, add a hook function to
  165. `fortran-mode-hook' to execute `(fortran-auto-fill-mode 1)'.  *Note
  166. Hooks::.
  167. File: emacs,  Node: Fortran Columns,  Next: Fortran Abbrev,  Prev: Fortran Autofill,  Up: Fortran
  168. Columns
  169. -------
  170. `C-c C-r'
  171.      Display a "column ruler" momentarily above the current line
  172.      (`fortran-column-ruler').
  173. `C-c C-w'
  174.      Split the current window horizontally temporarily so that it is 72
  175.      columns wide.  This may help you avoid making lines longer than
  176.      the 72 character limit that some fortran compilers impose
  177.      (`fortran-window-create-momentarily').
  178.    The command `C-c C-r' (`fortran-column-ruler') shows a column ruler
  179. momentarily above the current line.  The comment ruler is two lines of
  180. text that show you the locations of columns with special significance in
  181. Fortran programs.  Square brackets show the limits of the columns for
  182. line numbers, and curly brackets show the limits of the columns for the
  183. statement body.  Column numbers appear above them.
  184.    Note that the column numbers count from zero, as always in GNU Emacs.
  185. As a result, the numbers may be one less than those you are familiar
  186. with; but the positions they indicate in the line are standard for
  187. Fortran.
  188.    The text used to display the column ruler is the value of the
  189. variable `fortran-comment-ruler'.  By changing this variable, you can
  190. change the display.
  191.    For even more help, use `C-c C-w' (`fortran-window-create'), a
  192. command which splits the current window horizontally, making a window 72
  193. columns wide.  By editing in this window you can immediately see when
  194. you make a line too wide to be correct Fortran.
  195. File: emacs,  Node: Fortran Abbrev,  Prev: Fortran Columns,  Up: Fortran
  196. Fortran Keyword Abbrevs
  197. -----------------------
  198.    Fortran mode provides many built-in abbrevs for common keywords and
  199. declarations.  These are the same sort of abbrev that you can define
  200. yourself.  To use them, you must turn on Abbrev mode.  *Note Abbrevs::.
  201.    The built-in abbrevs are unusual in one way: they all start with a
  202. semicolon.  You cannot normally use semicolon in an abbrev, but Fortran
  203. mode makes this possible by changing the syntax of semicolon to "word
  204. constituent."
  205.    For example, one built-in Fortran abbrev is `;c' for `continue'.  If
  206. you insert `;c' and then insert a punctuation character such as a space
  207. or a newline, the `;c' expands automatically to `continue', provided
  208. Abbrev mode is enabled.
  209.    Type `;?' or `;C-h' to display a list of all the built-in Fortran
  210. abbrevs and what they stand for.
  211. File: emacs,  Node: Asm Mode,  Prev: Fortran,  Up: Programs
  212. Asm Mode
  213. ========
  214.    Asm mode is a major mode for editing files of assembler code.  It
  215. defines these commands:
  216. `TAB'
  217.      `tab-to-tab-stop'.
  218. `LFD'
  219.      Insert a newline and then indent using `tab-to-tab-stop'.
  220.      Insert a colon and then remove the indentation from before the
  221.      label preceding colon.  Then do `tab-to-tab-stop'.
  222.      Insert or align a comment.
  223.    The variable `asm-comment-char' specifies which character starts
  224. comments in assembler syntax.
  225. File: emacs,  Node: Building,  Next: Abbrevs,  Prev: Programs,  Up: Top
  226. Compiling and Testing Programs
  227. ******************************
  228.    The previous chapter discusses the Emacs commands that are useful for
  229. making changes in programs.  This chapter deals with commands that
  230. assist in the larger process of developing and maintaining programs.
  231. * Menu:
  232. * Compilation::                   Compiling programs in languages other
  233.                                     than Lisp (C, Pascal, etc.)
  234. * Debuggers::                      Running symbolic debuggers for
  235.                                     non-Lisp programs.
  236. * Executing Lisp::                Various modes for editing Lisp programs,
  237.                                     with different facilities for running
  238.                                     the Lisp programs.
  239. * Libraries: Lisp Libraries.      Creating Lisp programs to run in Emacs.
  240. * Interaction: Lisp Interaction.  Executing Lisp in an Emacs buffer.
  241. * Eval: Lisp Eval.                Executing a single Lisp expression in Emacs.
  242. * External Lisp::                 Communicating through Emacs with a
  243.                                     separate Lisp.
  244. File: emacs,  Node: Compilation,  Next: Debuggers,  Up: Building
  245. Running `make', or Compilers Generally
  246. ======================================
  247.    Emacs can run compilers for noninteractive languages such as C and
  248. Fortran as inferior processes, feeding the error log into an Emacs
  249. buffer.  It can also parse the error messages and show you the source
  250. lines where compilation errors occurred.
  251. `M-x compile'
  252.      Run a compiler asynchronously under Emacs, with error messages to
  253.      `*compilation*' buffer.
  254. `M-x grep'
  255.      Run `grep' asynchronously under Emacs, with matching lines listed
  256.      in the buffer named `*grep*'.
  257. `M-x kill-compilation'
  258. `M-x kill-grep'
  259.      Kill the running compilation or `grep' subprocess.
  260. `C-x `'
  261.      Visit the locus of the next compiler error message or `grep' match.
  262.    To run `make' or another compilation command, do `M-x compile'.
  263. This command reads a shell command line using the minibuffer, and then
  264. executes the command in an inferior shell, putting output in the buffer
  265. named `*compilation*'.  The current buffer's default directory is used
  266. as the working directory for the execution of the command; normally,
  267. therefore, the compilation happens in this directory.
  268.    When the shell command line is read, the minibuffer appears
  269. containing a default command line, which is the command you used the
  270. last time you did `M-x compile'.  If you type just RET, the same command
  271. line is used again.  For the first `M-x compile', the default is `make
  272.    The default compilation command comes from the variable
  273. `compile-command'; if the appropriate compilation command for a file is
  274. something other than `make -k', it can be useful for the file to
  275. specify a local value for `compile-command' (*note File Variables::.).
  276.    Starting a compilation displays the buffer `*compilation*' in
  277. another window but does not select it.  The buffer's mode line tells you
  278. whether compilation is finished, with the word `run' or `exit' inside
  279. the parentheses.  You do not have to keep this buffer visible;
  280. compilation continues in any case.  While a compilation is going on, the
  281. string `Compiling' appears in the mode lines of all windows.  When this
  282. string disappears, the compilation is finished.
  283.    To kill the compilation process, do `M-x kill-compilation'.  When
  284. the compiler process terminates, the mode line of the `*compilation*'
  285. buffer changes to say `signal' instead of `run'.  Starting a new
  286. compilation also kills any running compilation, as only one can exist
  287. at any time.  However, `M-x compile' asks for confirmation before
  288. actually killing a compilation that is running.
  289.    The `*compilation*' buffer uses a special major mode, Compilation
  290. mode.  This mode provides the keys SPC and DEL to scroll by screenfuls,
  291. and `M-n' and `M-p' to move to the next or previous error message.  You
  292. can also use `M-{' and `M-}' to move up or down to an error message for
  293. a different source file.  You can visit the source for any particular
  294. error message by moving point in `*compilation*' to that error message
  295. and typing `C-c C-c' (`compile-goto-error').
  296.    To parse the compiler error messages sequentially, type `C-x `'
  297. (`next-error').  The character following the `C-x' is the backquote or
  298. "grave accent," not the single-quote.  This command is available in all
  299. buffers, not just in `*compilation*'.  It displays the next error
  300. message at the top of one window and source location of the error in
  301. another window.
  302.    The first time `C-x `' is used after the start of a compilation, it
  303. moves to the first error's location.  Subsequent uses of `C-x `'
  304. advance down the data set up by the first use.  When the preparsed error
  305. messages are exhausted, the next `C-x `' checks for any more error
  306. messages that have come in; this is useful if you start editing the
  307. compilation errors while the compilation is still going on.  If no more
  308. error messages have come in, `C-x `' reports an error.
  309.    `C-u C-x `' discards the preparsed error message data and parses the
  310. `*compilation*' buffer over again, then displaying the first error.
  311. This way, you can process the same set of errors again.
  312.    Instead of running a compiler, you can run `grep' and see the lines
  313. on which matches were found.  To do this, type `M-x grep' with an
  314. argument line that contains the same arguments you would give `grep'
  315. when running it normally: a `grep'-style regexp (usually in
  316. single-quotes to quote the shell's special characters) followed by file
  317. names which may use wildcards.  The output from `grep' goes in the
  318. `*grep*' buffer and the lines that matched can be found with `C-x `' as
  319. if they were compilation errors.
  320.    Note: a shell is used to run the compile command, but the shell is
  321. told that it should be noninteractive.  This means in particular that
  322. the shell starts up with no prompt.  If you find your usual shell
  323. prompt making an unsightly appearance in the `*compilation*' buffer, it
  324. means you have made a mistake in your shell's init file (`.cshrc' or
  325. `.shrc' or ...) by setting the prompt unconditionally.  The shell init
  326. file should set the prompt only if there already is a prompt.  In
  327. `csh', here is how to do it:
  328.      if ($?prompt) set prompt = ...
  329. File: emacs,  Node: Debuggers,  Next: Executing Lisp,  Prev: Compilation,  Up: Building
  330. Running Debuggers Under Emacs
  331. =============================
  332.    The GUD (Grand Unified Debugger) library provides an interface to
  333. various symbolic debuggers from within Emacs.  We recommend the
  334. debugger GDB, which is free software, but you can also run DBX or SDB
  335. if you have them.
  336. * Menu:
  337. * Starting GUD::    How to start a debugger subprocess.
  338. * Debugger Operation::    Connection between the debugger and source buffers.
  339. * Commands of GUD::    Keybindings for common commands.
  340. * GUD Customization::    Defining your own commands for GUD.
  341. File: emacs,  Node: Starting GUD,  Next: Debugger Operation,  Up: Debuggers
  342. Starting GUD
  343. ------------
  344.    There are three commands for starting a debugger, each corresponding
  345. to a particular debugger program.
  346. `M-x gdb RET FILE RET'
  347.      Run GDB as a subprocess of Emacs.  This command creates a buffer
  348.      for input and output to GDB, and switches to it.  If a GDB buffer
  349.      already exists, it just switches to that buffer.
  350. `M-x dbx RET FILE RET'
  351.      Similar, but run DBX instead of GDB.
  352. `M-x sdb RET FILE RET'
  353.      Similar, but run SDB instead of GDB.
  354.      Some versions of SDB do not mention source file names in their
  355.      messages.  When you use them, you need to have a valid tags table
  356.      (*note Tags::.) in order for GUD to find functions in the source
  357.      code.  If you have not visited a tags table or the tags table
  358.      doesn't list one of the functions, you get a message saying `The
  359.      sdb support requires a valid tags table to work'.  If this
  360.      happens, generate a valid tags table in the working directory and
  361.      try again.
  362. `M-x xdb'
  363.      Similar, but run XDB instead of GDB.
  364.    You can only run one debugger process at a time.
  365.    Each of these commands takes one argument: a command line to invoke
  366. the debugger.  In the simplest case, specify just the name of the
  367. executable file you want to debug.  You may also use options that the
  368. debugger supports.  However, shell wild cards and variables are not
  369. allowed.  GUD assumes that the first argument not preceded by a `-' is
  370. the executable file name.
  371. File: emacs,  Node: Debugger Operation,  Next: Commands of GUD,  Prev: Starting GUD,  Up: Debuggers
  372. Debugger Operation
  373. ------------------
  374.    When you run a debugger with GUD, the debugger uses an Emacs buffer
  375. for its ordinary input and output.  This is called the GUD buffer.  The
  376. debugger uses other Emacs buffers to display the source files of the
  377. program.  An arrow (`=>') in one of these buffers indicates the current
  378. execution line.  Moving point in this buffer does not move the arrow.
  379.    You can start editing these source files at any time in the buffers
  380. that were made to display them.  The arrow is not part of the file's
  381. text; it appears only on the screen.  If you do modify a source file,
  382. keep in mind that inserting or deleting lines will throw off the arrow's
  383. positioning; GUD has no way of figuring out which line corresponded
  384. before your changes to the line number in a debugger message.  Also,
  385. you'll typically have to recompile and restart the program for your
  386. changes to be reflected in the debugger's tables.
  387.    If you wish, you can control your debugger process entirely through
  388. the debugger buffer, which uses a variant of Shell mode.  All the usual
  389. commands for your debugger are available, and you can use the Shell mode
  390. history commands to repeat them.
  391. File: emacs,  Node: Commands of GUD,  Next: GUD Customization,  Prev: Debugger Operation,  Up: Debuggers
  392. Commands of GUD
  393. ---------------
  394.    GUD provides a command available in all buffers for setting
  395. breakpoints.  This command is defined globally because you need to use
  396. it in the source files' buffers.
  397. `C-x SPC'
  398.      Set a breakpoint on the line that point is on.
  399.    Here are the other commands provided by GUD.  The keys starting with
  400. `C-c' are available only in the GUD interaction buffer.  The bindings
  401. that start with `C-x C-a' are available in the GUD buffer and also in
  402. source files.
  403. `C-c C-l'
  404. `C-x C-a C-l'
  405.      Display in another window the last line referred to in the GUD
  406.      buffer (that is, the line indicated in the last location message).
  407.      This runs the command `gud-refresh'.
  408. `C-c C-s'
  409. `C-x C-a C-s'
  410.      Execute a single line of code (`gud-step').  If the code contains
  411.      a function call, execution stops after entering the called
  412.      function.
  413. `C-c C-n'
  414. `C-x C-a C-n'
  415.      Execute a single line of code, stepping across entire function
  416.      calls at full speed (`gud-next').
  417. `C-c C-i'
  418. `C-x C-a C-i'
  419.      Execute a single machine instruction (`gud-stepi').
  420. `C-c C-c'
  421. `C-x C-a C-c'
  422.      Continue execution until the next breakpoint, or other event that
  423.      would normally stop the program (`gud-cont').
  424. `C-c C-d'
  425. `C-x C-a C-d'
  426.      Delete the breakpoint(s) on the current source line, if any
  427.      (`gud-remove').  If you use this command in the GUD interaction
  428.      buffer, it applies to the line where the program last stopped.
  429. `C-c C-t'
  430. `C-x C-a C-t'
  431.      Set a temporary breakpoint on the current source line, if any.  If
  432.      you use this command in the GUD interaction buffer, it applies to
  433.      the line where the program last stopped.
  434.    The above commands are common to all supported debuggers.  If you are
  435. using GDB or (some versions of) DBX, these additional commands are
  436. available:
  437. `C-c <'
  438. `C-x C-a <'
  439.      Select the next enclosing stack frame (`gud-up').  This is
  440.      equivalent to the `up' command.
  441. `C-c >'
  442. `C-x C-a >'
  443.      Select the next inner stack frame (`gud-down').  This is
  444.      equivalent to the `down' command.
  445.    If you are using GDB, two additional keybindings are available:
  446. `C-c C-f'
  447. `C-x C-a C-f'
  448.      Run the program until the selected stack frame returns (or until it
  449.      stops for some other reason).
  450.    These commands interpret a prefix argument as a repeat count, when
  451. that makes sense.
  452. File: emacs,  Node: GUD Customization,  Prev: Commands of GUD,  Up: Debuggers
  453. GUD Customization
  454. -----------------
  455.    On startup, GUD runs one of the following hooks: `gdb-mode-hook', if
  456. you are using GDB; `dbx-mode-hook', if you are using DBX;
  457. `sdb-mode-hook', if you are using SDB; and `xdb-mode-hook', if you are
  458. using XDB.  You can use these hooks to define custom keybindings for
  459. the debugger interaction buffer.  *Note Hooks::.
  460.    Here is a convenient way to define a command that sends a particular
  461. command string to the debugger, and set up a key binding for it in the
  462. debugger interaction buffer:
  463.      (gud-def FUNCTION CMDSTRING BINDING DOCSTRING)
  464.    This defines a command named FUNCTION which sends CMDSTRING to the
  465. debugger process, with documentation string DOCSTRING.  You can use the
  466. command thus defined in any buffer.  If BINDING is non-`nil', `gud-def'
  467. also binds the command to `C-c BINDING' in the GUD buffer's mode and to
  468. `C-x C-a BINDING' generally.
  469.    The command string CMDSTRING may contain certain escape sequences
  470. that are filled in with varying data at the time FUNCTION is called:
  471.      Name of the current source file.  If the current buffer is the GUD
  472.      buffer, then the "current source file" is the file that the
  473.      program stopped in.
  474.      Number of the current source line.  If the current buffer is the
  475.      GUD buffer, then the "current source line" is the line that the
  476.      program stopped in.
  477.      Text of the C lvalue or function-call expression surrounding point.
  478.      Text of the hexadecimal address surrounding point.
  479.      Prefix (numeric) argument of the called function (if any) as a
  480.      number.  (If you don't use `%p' in the command string, the command
  481.      you define ignores any prefix argument.)
  482. File: emacs,  Node: Executing Lisp,  Next: Lisp Libraries,  Prev: Debuggers,  Up: Building
  483. Executing Lisp Expressions
  484. ==========================
  485.    Emacs has several different major modes for Lisp and Scheme.  They
  486. are the same in terms of editing commands, but differ in the commands
  487. for executing Lisp expressions.
  488. Emacs-Lisp mode
  489.      The mode for editing source files of programs to run in Emacs Lisp.
  490.      This mode defines `C-M-x' to evaluate the current defun.  *Note
  491.      Lisp Libraries::.
  492. Lisp Interaction mode
  493.      The mode for an interactive session with Emacs Lisp.  It defines
  494.      LFD to evaluate the sexp before point and insert its value in the
  495.      buffer.  *Note Lisp Interaction::.
  496. Lisp mode
  497.      The mode for editing source files of programs that run in Lisps
  498.      other than Emacs Lisp.  This mode defines `C-M-x' to send the
  499.      current defun to an inferior Lisp process.  *Note External Lisp::.
  500. Inferior Lisp mode
  501.      The mode for an interactive session with an inferior Lisp process.
  502.      This mode combines the special features of Lisp mode and Shell mode
  503.      (*note Shell Mode::.).
  504. Scheme mode
  505.      Like Lisp mode but for Scheme programs.
  506. Inferior Scheme mode
  507.      The mode for an interactive session with an inferior Scheme
  508.      process.
  509. * Menu:
  510. These subnodes of the chapter on editing programs describe the editing
  511. commands for working with Lisp programs, which are in fact available
  512. globally.
  513. * Lists::               Expressions with balanced parentheses.
  514. * List Commands::       The commands for working with list and sexps.
  515. * Defuns::              Each program is made up of separate functions.
  516.                           There are editing commands to operate on them.
  517. * Program Indent::      Adjusting indentation to show the nesting.
  518. * Matching::            Insertion of a close-delimiter flashes matching open.
  519. * Comments::            Inserting, killing, and aligning comments.
  520. File: emacs,  Node: Lisp Libraries,  Next: Lisp Interaction,  Prev: Executing Lisp,  Up: Building
  521. Libraries of Lisp Code for Emacs
  522. ================================
  523.    Lisp code for Emacs editing commands is stored in files whose names
  524. conventionally end in `.el'.  This ending tells Emacs to edit them in
  525. Emacs-Lisp mode (*note Executing Lisp::.).
  526.    To execute a file of Emacs Lisp code, use `M-x load-file'.  This
  527. command reads a file name using the minibuffer and then executes the
  528. contents of that file as Lisp code.  It is not necessary to visit the
  529. file first; in any case, this command reads the file as found on disk,
  530. not text in an Emacs buffer.
  531.    Once a file of Lisp code is installed in the Emacs Lisp library
  532. directories, users can load it using `M-x load-library'.  Programs can
  533. load it by calling `load-library', or with `load', a more primitive
  534. function that is similar but accepts some additional arguments.
  535.    `M-x load-library' differs from `M-x load-file' in that it searches
  536. a sequence of directories and tries three file names in each directory.
  537. Suppose your argument is LIB; the three names are `LIB.elc', `LIB.el',
  538. and lastly just `LIB'.  If `LIB.elc' exists, it is by convention the
  539. result of compiling `LIB.el'; it is better to load the compiled file,
  540. since it will load and run faster.
  541.    If `load-library' finds that `LIB.el' is newer than `LIB.elc' file,
  542. it prints a warning, because it's likely that somebody made changes to
  543. the `.el' file and forgot to recompile it.
  544.    Because the argument to `load-library' is usually not in itself a
  545. valid file name, file name completion is not available.  Indeed, when
  546. using this command, you usually do not know exactly what file name will
  547. be used.
  548.    The sequence of directories searched by `M-x load-library' is
  549. specified by the variable `load-path', a list of strings that are
  550. directory names.  The default value of the list contains the directory
  551. where the Lisp code for Emacs itself is stored.  If you have libraries
  552. of your own, put them in a single directory and add that directory to
  553. `load-path'.  `nil' in this list stands for the current default
  554. directory, but it is probably not a good idea to put `nil' in the list.
  555. If you find yourself wishing that `nil' were in the list, most likely
  556. what you really want to do is use `M-x load-file' this once.
  557.    Often you do not have to give any command to load a library, because
  558. the commands defined in the library are set up to "autoload" that
  559. library.  Running any of those commands causes `load' to be called to
  560. load the library; this replaces the autoload definitions with the real
  561. ones from the library.
  562.    If autoloading a file does not finish, either because of an error or
  563. because of a `C-g' quit, all function definitions made by the file are
  564. undone automatically.  So are any calls to `provide'.  As a consequence,
  565. if you use one of the autoloadable commands again, the entire file will
  566. be loaded a second time.  This prevents problems where the command is no
  567. longer autoloading but it works wrong because not all the file was
  568. loaded.  Function definitions are undone only for autoloading; explicit
  569. calls to `load' do not undo anything if loading is not completed.
  570.    Emacs Lisp code can be compiled into byte-code which loads faster,
  571. takes up less space when loaded, and executes faster.  *Note Byte
  572. Compilation: (elisp)Byte Compilation.
  573.    By convention, the compiled code for a library goes in a separate
  574. file whose name consists of the library source file with `c' appended.
  575. Thus, the compiled code for `foo.el' goes in `foo.elc'.  That's why
  576. `load-library' searches for `.elc' files first.
  577. File: emacs,  Node: Lisp Eval,  Next: External Lisp,  Prev: Lisp Interaction,  Up: Building
  578. Evaluating Emacs-Lisp Expressions
  579. =================================
  580.    Lisp programs intended to be run in Emacs should be edited in
  581. Emacs-Lisp mode; this happens automatically for file names ending in
  582. `.el'.  By contrast, Lisp mode itself is used for editing Lisp programs
  583. intended for other Lisp systems.  To switch to Emacs-Lisp mode
  584. explicitly, use the command `M-x emacs-lisp-mode'.
  585.    For testing of Lisp programs to run in Emacs, it is often useful to
  586. evaluate part of the program as it is found in the Emacs buffer.  For
  587. example, after changing the text of a Lisp function definition,
  588. evaluating the definition installs the change for future calls to the
  589. function.  Evaluation of Lisp expressions is also useful in any kind of
  590. editing, for invoking noninteractive functions (functions that are not
  591. commands).
  592. `M-ESC'
  593.      Read a single Lisp expression in the minibuffer, evaluate it, and
  594.      print the value in the echo area (`eval-expression').
  595. `C-x C-e'
  596.      Evaluate the Lisp expression before point, and print the value in
  597.      the echo area (`eval-last-sexp').
  598. `C-M-x'
  599.      Evaluate the defun containing or after point, and print the value
  600.      in the echo area (`eval-defun').
  601. `M-x eval-region'
  602.      Evaluate all the Lisp expressions in the region.
  603. `M-x eval-current-buffer'
  604.      Evaluate all the Lisp expressions in the buffer.
  605.    `M-ESC' (`eval-expression') is the most basic command for evaluating
  606. a Lisp expression interactively.  It reads the expression using the
  607. minibuffer, so you can execute any expression on a buffer regardless of
  608. what the buffer contains.  When the expression is evaluated, the current
  609. buffer is once again the buffer that was current when `M-ESC' was typed.
  610.    `M-ESC' can easily confuse users who do not understand it,
  611. especially on keyboards with autorepeat where it can result from holding
  612. down the ESC key for too long.  Therefore, `eval-expression' is
  613. normally a disabled command.  Attempting to use this command asks for
  614. confirmation and gives you the option of enabling it; once you enable
  615. the command, confirmation will no longer be required for it.  *Note
  616. Disabling::.
  617.    In Emacs-Lisp mode, the key `C-M-x' is bound to the command
  618. `eval-defun', which parses the defun containing or following point as a
  619. Lisp expression and evaluates it.  The value is printed in the echo
  620. area.  This command is convenient for installing in the Lisp environment
  621. changes that you have just made in the text of a function definition.
  622.    The command `C-x C-e' (`eval-last-sexp') performs a similar job but
  623. is available in all major modes, not just Emacs-Lisp mode.  It finds
  624. the sexp before point, reads it as a Lisp expression, evaluates it, and
  625. prints the value in the echo area.  It is sometimes useful to type in an
  626. expression and then, with point still after it, type `C-x C-e'.
  627.    If `C-M-x' or `C-x C-e' is given a numeric argument, it prints the
  628. value by insertion into the current buffer at point, rather than in the
  629. echo area.  The argument value does not matter.
  630.    The most general command for evaluating Lisp expressions from a
  631. buffer is `eval-region'.  `M-x eval-region' parses the text of the
  632. region as one or more Lisp expressions, evaluating them one by one.
  633. `M-x eval-current-buffer' is similar but evaluates the entire buffer.
  634. This is a reasonable way to install the contents of a file of Lisp code
  635. that you are just ready to test.  After finding and fixing a bug, use
  636. `C-M-x' on each function that you change, to keep the Lisp world in
  637. step with the source file.
  638. File: emacs,  Node: Lisp Interaction,  Next: Lisp Eval,  Prev: Lisp Libraries,  Up: Building
  639. Lisp Interaction Buffers
  640. ========================
  641.    The buffer `*scratch*' which is selected when Emacs starts up is
  642. provided for evaluating Lisp expressions interactively inside Emacs.
  643.    Thus, the way to use the `*scratch*' buffer is to insert Lisp
  644. expressions at the end, ending each one with LFD so that it will be
  645. evaluated.  This command reads the Lisp expression before point,
  646. evaluates it, and inserts the value in printed representation before
  647. point.  The result is a complete typescript of the expressions you have
  648. evaluated and their values.
  649.    The `*scratch*' buffer's major mode is Lisp Interaction mode, which
  650. is the same as Emacs-Lisp mode except for the binding of LFD.
  651.    The rationale for this feature is that Emacs must have a buffer when
  652. it starts up, but that buffer is not useful for editing files since a
  653. new buffer is made for every file that you visit.  The Lisp interpreter
  654. typescript is the most useful thing I can think of for the initial
  655. buffer to do.  Type `M-x lisp-interaction-mode' to put the current
  656. buffer in Lisp Interaction mode.
  657. File: emacs,  Node: External Lisp,  Prev: Lisp Eval,  Up: Building
  658. Running an External Lisp
  659. ========================
  660.    Emacs has facilities for running programs in other Lisp systems.
  661. You can run a Lisp process as an inferior of Emacs, and pass
  662. expressions to it to be evaluated.  You can also pass changed function
  663. definitions directly from the Emacs buffers in which you edit the Lisp
  664. programs to the inferior Lisp process.
  665.    To run an inferior Lisp process, type `M-x run-lisp'.  This runs the
  666. program named `lisp', the same program you would run by typing `lisp'
  667. as a shell command, with both input and output going through an Emacs
  668. buffer named `*lisp*'.  That is to say, any "terminal output" from Lisp
  669. will go into the buffer, advancing point, and any "terminal input" for
  670. Lisp comes from text in the buffer.  (You can change the name of the
  671. Lisp executable file by setting the variable `inferior-lisp-program'.)
  672.    To give input to Lisp, go to the end of the buffer and type the
  673. input, terminated by RET.  The `*lisp*' buffer is in Inferior Lisp
  674. mode, which combines the special characteristics of Lisp mode and Shell
  675. mode (*note Shell Mode::.).
  676.    For the source files of programs to run in external Lisps, use Lisp
  677. mode.  This mode can be selected with `M-x lisp-mode', and is used
  678. automatically for files whose names end in `.l' or `.lisp', as most Lisp
  679. systems usually expect.
  680.    When you edit a function in a Lisp program you are running, the
  681. easiest way to send the changed definition to the inferior Lisp process
  682. is the key `C-M-x'.  In Lisp mode, this runs the function
  683. `lisp-send-defun', which finds the defun around or following point and
  684. sends it as input to the Lisp process.  (Emacs can send input to any
  685. inferior process regardless of what buffer is current.)
  686.    Contrast the meanings of `C-M-x' in Lisp mode (for editing programs
  687. to be run in another Lisp system) and Emacs-Lisp mode (for editing Lisp
  688. programs to be run in Emacs): in both modes it has the effect of
  689. installing the function definition that point is in, but the way of
  690. doing so is different according to where the relevant Lisp environment
  691. is found.  *Note Executing Lisp::.
  692. File: emacs,  Node: Abbrevs,  Next: Picture,  Prev: Building,  Up: Top
  693. Abbrevs
  694. *******
  695.    An "abbrev" is a word which "expands", if you insert it, into some
  696. different text.  Abbrevs are defined by the user to expand in specific
  697. ways.  For example, you might define `foo' as an abbrev expanding to
  698. `find outer otter'.  With this abbrev defined, you would be able to get
  699. `find outer otter ' into the buffer by typing `f o o SPC'.
  700.    Abbrevs expand only when Abbrev mode (a minor mode) is enabled.
  701. Disabling Abbrev mode does not cause abbrev definitions to be forgotten,
  702. but they do not expand until Abbrev mode is enabled again.  The command
  703. `M-x abbrev-mode' toggles Abbrev mode; with a numeric argument, it
  704. turns Abbrev mode on if the argument is positive, off otherwise.  *Note
  705. Minor Modes::.  `abbrev-mode' is also a variable; Abbrev mode is on
  706. when the variable is non-`nil'.  The variable `abbrev-mode'
  707. automatically becomes local to the current buffer when it is set.
  708.    Abbrev definitions can be "mode-specific"--active only in one major
  709. mode.  Abbrevs can also have "global" definitions that are active in
  710. all major modes.  The same abbrev can have a global definition and
  711. various mode-specific definitions for different major modes.  A mode
  712. specific definition for the current major mode overrides a global
  713. definition.
  714.    Abbrevs can be defined interactively during the editing session.
  715. Lists of abbrev definitions can also be saved in files and reloaded in
  716. later sessions.  Some users keep extensive lists of abbrevs that they
  717. load in every session.
  718.    A second kind of abbreviation facility is called the "dynamic
  719. expansion".  Dynamic abbrev expansion happens only when you give an
  720. explicit command and the result of the expansion depends only on the
  721. current contents of the buffer.  *Note Dynamic Abbrevs::.
  722. * Menu:
  723. * Defining Abbrevs::  Defining an abbrev, so it will expand when typed.
  724. * Expanding Abbrevs:: Controlling expansion: prefixes, canceling expansion.
  725. * Editing Abbrevs::   Viewing or editing the entire list of defined abbrevs.
  726. * Saving Abbrevs::    Saving the entire list of abbrevs for another session.
  727. * Dynamic Abbrevs::   Abbreviations for words already in the buffer.
  728. File: emacs,  Node: Defining Abbrevs,  Next: Expanding Abbrevs,  Up: Abbrevs
  729. Defining Abbrevs
  730. ================
  731. `C-x a g'
  732.      Define an abbrev, using one or more words before point as its
  733.      expansion (`add-global-abbrev').
  734. `C-x a l'
  735.      Similar, but define an abbrev specific to the current major mode
  736.      (`add-mode-abbrev').
  737. `C-x a i g'
  738.      Define a word in the buffer as an abbrev
  739.      (`inverse-add-global-abbrev').
  740. `C-x a i l'
  741.      Define a word in the buffer as a mode-specific abbrev
  742.      (`inverse-add-mode-abbrev').
  743. `M-x kill-all-abbrevs'
  744.      After this command, there are no abbrev definitions in effect.
  745.    The usual way to define an abbrev is to enter the text you want the
  746. abbrev to expand to, position point after it, and type `C-x a g'
  747. (`add-global-abbrev').  This reads the abbrev itself using the
  748. minibuffer, and then defines it as an abbrev for one or more words
  749. before point.  Use a numeric argument to say how many words before
  750. point should be taken as the expansion.  For example, to define the
  751. abbrev `foo' as mentioned above, insert the text `find outer otter' and
  752. then type `C-u 3 C-x a g f o o RET'.
  753.    An argument of zero to `C-x a g' means to use the contents of the
  754. region as the expansion of the abbrev being defined.
  755.    The command `C-x a l' (`add-mode-abbrev') is similar, but defines a
  756. mode-specific abbrev.  Mode specific abbrevs are active only in a
  757. particular major mode.  `C-x a l' defines an abbrev for the major mode
  758. in effect at the time `C-x a l' is typed.  The arguments work the same
  759. as for `C-x a g'.
  760.    If the text of the abbrev you want is already in the buffer instead
  761. of the expansion, use command `C-x a i g' (`inverse-add-global-abbrev')
  762. instead of `C-x a g', or use `C-x a i l' (`inverse-add-mode-abbrev')
  763. instead of `C-x a l'.  These commands are called "inverse" because they
  764. invert the meaning of the argument found in the buffer and the argument
  765. read using the minibuffer.
  766.    To change the definition of an abbrev, just add the new definition.
  767. You will be asked to confirm if the abbrev has a prior definition.  To
  768. remove an abbrev definition, give a negative argument to `C-x a g' or
  769. `C-x a l'.  You must choose the command to specify whether to kill a
  770. global definition or a mode-specific definition for the current mode,
  771. since those two definitions are independent for one abbrev.
  772.    `M-x kill-all-abbrevs' removes all the abbrev definitions there are.
  773. File: emacs,  Node: Expanding Abbrevs,  Next: Editing Abbrevs,  Prev: Defining Abbrevs,  Up: Abbrevs
  774. Controlling Abbrev Expansion
  775. ============================
  776.    An abbrev expands whenever it is present in the buffer just before
  777. point and a self-inserting punctuation character (SPC, comma, etc.) is
  778. typed.  Most often the way an abbrev is used is to insert the abbrev
  779. followed by punctuation.
  780.    Abbrev expansion preserves case; thus, `foo' expands into `find
  781. outer otter'; `Foo' into `Find outer otter', and `FOO' into `FIND OUTER
  782. OTTER' or `Find Outer Otter' according to the variable
  783. `abbrev-all-caps' (a non-`nil' value chooses the first of the two
  784. expansions).
  785.    These two commands are used to control abbrev expansion:
  786. `M-''
  787.      Separate a prefix from a following abbrev to be expanded
  788.      (`abbrev-prefix-mark').
  789. `C-x a e'
  790.      Expand the abbrev before point (`expand-abbrev').  This is
  791.      effective even when Abbrev mode is not enabled.
  792. `M-x unexpand-abbrev'
  793.      Undo last abbrev expansion.
  794. `M-x expand-region-abbrevs'
  795.      Expand some or all abbrevs found in the region.
  796.    You may wish to expand an abbrev with a prefix attached; for
  797. example, if `cnst' expands into `construction', you might want to use
  798. it to enter `reconstruction'.  It does not work to type `recnst',
  799. because that is not necessarily a defined abbrev.  What does work is to
  800. use the command `M-'' (`abbrev-prefix-mark') in between the prefix `re'
  801. and the abbrev `cnst'.  First, insert `re'.  Then type `M-''; this
  802. inserts a minus sign in the buffer to indicate that it has done its
  803. work.  Then insert the abbrev `cnst'; the buffer now contains
  804. `re-cnst'.  Now insert a punctuation character to expand the abbrev
  805. `cnst' into `construction'.  The minus sign is deleted at this point,
  806. because `M-'' left word for this to be done.  The resulting text is the
  807. desired `reconstruction'.
  808.    If you actually want the text of the abbrev in the buffer, rather
  809. than its expansion, you can accomplish this by inserting the following
  810. punctuation with `C-q'.  Thus, `foo C-q -' leaves `foo-' in the buffer.
  811.    If you expand an abbrev by mistake, you can undo the expansion
  812. (replace the expansion by the original abbrev text) with `M-x
  813. unexpand-abbrev'.  `C-_' (`undo') can also be used to undo the
  814. expansion; but first it undoes the insertion of the following
  815. punctuation character.  Therefore, if you want both the punctuation
  816. character and the unexpanded abbrev, you must reinsert the punctuation
  817. character, quoting it with `C-q'.
  818.    `M-x expand-region-abbrevs' searches through the region for defined
  819. abbrevs, and for each one found offers to replace it with its expansion.
  820. This command is useful if you have typed in text using abbrevs but
  821. forgot to turn on Abbrev mode first.  It may also be useful together
  822. with a special set of abbrev definitions for making several global
  823. replacements at once.  This command is effective even if Abbrev mode is
  824. not enabled.
  825.    Expanding an abbrev runs the hook `pre-abbrev-expand-hook' (*note
  826. Hooks::.).
  827. File: emacs,  Node: Editing Abbrevs,  Next: Saving Abbrevs,  Prev: Expanding Abbrevs,  Up: Abbrevs
  828. Examining and Editing Abbrevs
  829. =============================
  830. `M-x list-abbrevs'
  831.      Print a list of all abbrev definitions.
  832. `M-x edit-abbrevs'
  833.      Edit a list of abbrevs; you can add, alter or remove definitions.
  834.    The output from `M-x list-abbrevs' looks like this:
  835.      (lisp-mode-abbrev-table)
  836.      "dk"           0    "define-key"
  837.      (global-abbrev-table)
  838.      "dfn"           0    "definition"
  839. (Some blank lines of no semantic significance, and some other abbrev
  840. tables, have been omitted.)
  841.    A line containing a name in parentheses is the header for abbrevs in
  842. a particular abbrev table; `global-abbrev-table' contains all the global
  843. abbrevs, and the other abbrev tables that are named after major modes
  844. contain the mode-specific abbrevs.
  845.    Within each abbrev table, each nonblank line defines one abbrev.  The
  846. word at the beginning is the abbrev.  The number that appears is the
  847. number of times the abbrev has been expanded.  Emacs keeps track of
  848. this to help you see which abbrevs you actually use, in case you decide
  849. to eliminate those that you don't use often.  The string at the end of
  850. the line is the expansion.
  851.    `M-x edit-abbrevs' allows you to add, change or kill abbrev
  852. definitions by editing a list of them in an Emacs buffer.  The list has
  853. the same format described above.  The buffer of abbrevs is called
  854. `*Abbrevs*', and is in Edit-Abbrevs mode.  This mode redefines the key
  855. `C-c C-c' to install the abbrev definitions as specified in the buffer.
  856. The command that does this is `edit-abbrevs-redefine'.  Any abbrevs
  857. not described in the buffer are eliminated when this is done.
  858.    The command `edit-abbrevs' is actually the same as `list-abbrevs'
  859. except that it selects the buffer `*Abbrevs*' whereas `list-abbrevs'
  860. merely displays it in another window.
  861.